﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraBars;
using QLTV.BLL;
using QLTV.Public;

namespace QLTV.GUI.Forms
{
    public partial class frmDangNhap : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        DangNhapBLL dnBLL;
        public string strTenTaiKhoan;

        private bool kt = false;

        public frmDangNhap()
        {
            InitializeComponent();
        }

        private void frmDangNhap_Load(object sender, EventArgs e)
        {
            dnBLL = new DangNhapBLL();
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtTenDN.Text.ToString()) || string.IsNullOrEmpty(txtMatKhau.Text.ToString()))
            {
                MessageBox.Show("Tên đăng nhập hoặc mật khẩu không được để trống.");
            }
            else
            {
                DangNhapDTO dnPublic = new DangNhapDTO();
                dnPublic.TenDangNhap = txtTenDN.Text.Trim();
                dnPublic.MatKhau = txtMatKhau.Text.Trim();
                DataTable dtDN = dnBLL.CheckDangNhap(dnPublic);
                if (dtDN.Rows.Count == 0)
                {
                    MessageBox.Show("Sai Tên Tài Khoản Hoặc Mật Khẩu", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtTenDN.Text = string.Empty;
                    txtMatKhau.Text = string.Empty;
                    return;
                }
                else
                {
                    kt = true;
                    Is_Send = true;
                    Forms.frmMain fM = new frmMain();
                    this.Hide();
                    fM.ShowDialog();
                }
            }         
           
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        public delegate void MyDelegate(object sender, bool check);
        public event MyDelegate myEvent;
        private bool Is_Send
        {
            set
            {
                if (value)
                {
                    if (myEvent != null) myEvent(sender: this, check: kt);
                }
            }
        } 
    }
}